import { LoadCoordinates } from "./constants";
import { SelectMaterial } from "./constants";

export interface CoordinateItem {
  name: string;
  id: string;
  is_selected: boolean;
  // TODO 类型定义
  value: LoadCoordinates;
  // type: string;
  xAxis: any;
  yAxis: any;
  zAxis: any;
  originalNode?: Coordinate | undefined;
  zNode?: Coordinate | undefined;
  xzPlanePoint?: Coordinate | undefined;
}
export interface coordinateItem {
  name: string;
  id: string;
  // color: string;
  include: string;
  description: string;
  definitionMode: string;
  originalNode: string;
  zNode: string;
  xzPlanePoint: string;
  coordinateType: string;
  size: string;
}
export interface Coordinate {
  partId?: number;
  nodeId?: number;
  x: number;
  y: number;
  z: number;
}

export interface NoteTcell {
  x: any;
  y: any;
  z: any;
}
export interface SelectedNode {
  originalNode: Coordinate | undefined;
  zNode: Coordinate | undefined;
  xzPlanePoint: Coordinate | undefined;
}
export interface SelectedCoordinate {
  originPoint: Coordinate | undefined;
  xPoint: Coordinate | undefined;
  yPoint: Coordinate | undefined;
  zPoint: Coordinate | undefined;
}
//计算模长
export function vectorLength(coordinate: Coordinate): number {
  return Math.sqrt(
    coordinate.x * coordinate.x +
      coordinate.y * coordinate.y +
      coordinate.z * coordinate.z
  );
}
//计算点积
export function dotProduct(
  coordinate1: Coordinate,
  coordinate2: Coordinate
): number {
  return (
    coordinate1.x * coordinate2.x +
    coordinate1.y * coordinate2.y +
    coordinate1.z * coordinate2.z
  );
}
//计算叉积
export function crossProduct(coordinate1: Coordinate, coordinate2: Coordinate) {
  return {
    x: coordinate1.y * coordinate2.z - coordinate1.z * coordinate2.y,
    y: coordinate1.z * coordinate2.x - coordinate1.x * coordinate2.z,
    z: coordinate1.x * coordinate2.y - coordinate1.y * coordinate2.x,
  };
}
//计算归一化
export function normalize(coordinate: Coordinate) {
  const len = Math.sqrt(
    coordinate.x * coordinate.x +
      coordinate.y * coordinate.y +
      coordinate.z * coordinate.z
  );
  return {
    x: coordinate.x / len,
    y: coordinate.y / len,
    z: coordinate.z / len,
  };
}
//计算减法
export function subtract(coordinate1: Coordinate, coordinate2: Coordinate) {
  return {
    x: coordinate1.x - coordinate2.x,
    y: coordinate1.y - coordinate2.y,
    z: coordinate1.z - coordinate2.z,
  };
}

// 设置偏移
export function setOffset(originalNode: Coordinate, Axis: Coordinate) {
  const zNe: number[] = [];
  if (Number(Axis.x.toFixed(6)) < 0) {
    zNe[0] = Number(originalNode.x) - 3.333333 + 1.5 * Number(Axis.x);
  } else if (Number(Axis.x.toFixed(6)) > 0) {
    zNe[0] = Number(originalNode.x) + 3.333333 + 1.5 * Number(Axis.x);
  } else {
    zNe[0] = Number(originalNode.x) + 0 + 1.5 * Number(Axis.x);
  }
  if (Number(Axis.y.toFixed(6)) < 0) {
    zNe[1] = Number(originalNode.y) - 3.333333 + 1.5 * Number(Axis.y);
  } else if (Number(Axis.y.toFixed(6)) > 0) {
    zNe[1] = Number(originalNode.y) + 3.333333 + 1.5 * Number(Axis.y);
  } else {
    zNe[1] = Number(originalNode.y) + 0 + 1.5 * Number(Axis.y);
  }
  if (Number(Axis.z.toFixed(6)) < 0) {
    zNe[2] = Number(originalNode.z) - 3.333333 + 1.5 * Number(Axis.z);
  } else if (Number(Axis.z.toFixed(6)) > 0) {
    zNe[2] = Number(originalNode.z) + 3.333333 + 1.5 * Number(Axis.z);
  } else {
    zNe[2] = Number(originalNode.z) + 1.5 * Number(Axis.z);
  }
  return [zNe[0], zNe[1], zNe[2]];
}

// 节点坐标系
export interface NodeCoordinates {
  name: string;
  id: number;
  is_selected: boolean;
  value: SelectMaterial;
}

export interface MaterialOrientationsItem {
  name: string;
  id: number;
  is_selected: boolean;
  value: SelectMaterial;
}
